Total Complexity | 2 |
Total Lines | 35 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | import { CommandHandler } from '@nestjs/cqrs'; |
||
9 | |||
10 | @CommandHandler(UpdateEventCommand) |
||
11 | export class UpdateEventCommandHandler extends AbstractEventCommandHandler { |
||
12 | constructor( |
||
13 | @Inject('ISchoolRepository') schoolRepository: ISchoolRepository, |
||
14 | @Inject('IUserRepository') userRepository: IUserRepository, |
||
15 | @Inject('IEventRepository') |
||
16 | private readonly eventRepository: IEventRepository, |
||
17 | ) { |
||
18 | super(schoolRepository, userRepository); |
||
19 | } |
||
20 | |||
21 | public async execute(command: UpdateEventCommand): Promise<string> { |
||
22 | const { id, date, summary, userId, schoolId } = command; |
||
23 | |||
24 | const event = await this.eventRepository.findOneById(id); |
||
25 | if (!event) { |
||
26 | throw new EventNotFoundException(); |
||
27 | } |
||
28 | |||
29 | const [ user, school ] = await Promise.all([ |
||
30 | this.getUser(userId), |
||
31 | this.getSchool(schoolId) |
||
32 | ]); |
||
33 | |||
34 | event.update( |
||
35 | date, |
||
36 | user, |
||
37 | school, |
||
38 | summary |
||
39 | ); |
||
40 | |||
41 | await this.eventRepository.save(event); |
||
42 | |||
43 | return event.getId(); |
||
44 | } |
||
46 |